﻿function load_province(id, file) {                                               //加载省份
    file = file ? file : '/templates/speciality/js/Province.xml';                                    //对应xml文件
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $("#txtCity").attr("disabled", true);
            $("#txtArea").attr("disabled", true);
            $(xml).find("Provinces Province").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                $("#txtProvince").append("<option value='" + id + "'>" + name + "</option>");
            });
            if (id > 0)
                $("#txtProvince option[value=" + id + "]").attr("selected", true);
            else
                $("#txtProvince option[index=0]").attr("selected", true);
        }

    });
}
function load_p(pid, spanid, file) {
    file = file ? file : '/templates/speciality/js/Province.xml';
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $(xml).find("Provinces Province").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                if (pid == id) {
                    $("#" + spanid).text(name);
                }
            });
        }
    });
}

function load_c(pid, cid, spanid, file) {
    file = file ? file : '/templates/speciality/js/City.xml';
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $(xml).find("Cities City[PID=" + pid + "]").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                if (cid == id) {
                    $("#" + spanid).text(name);
                }
            });
        }
    });
}

function load_a(cid, aid, spanid, file) {
    file = file ? file : '/templates/speciality/js/Area.xml';
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $(xml).find("Areas Area[PID=" + cid + "]").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                if (aid == id) {
                    $("#" + spanid).text(name);
                }
            });
        }
    });
}

function change_province(pid, id, file) {                                     //改变省份
    file = file ? file : '/templates/speciality/js/City.xml';                                    //对应xml文件
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $("#txtArea").attr("disabled", true);
            $("#txtArea option").remove();
            $("#txtArea").append("<option value=''>请选择区域</option>");
            $("#txtCity").removeAttr("disabled");
            $("#txtCity option").remove();
            $("#txtCity").append("<option value=''>请选择城市</option>");
            $(xml).find("Cities City[PID=" + pid + "]").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                $("#txtCity").append("<option value='" + id + "'>" + name + "</option>");
            });
            if (id > 0) {
                $("#txtCity option[value=" + id + "]").attr("selected", true);
            }
            else {
                $("#txtCity option[index=0]").attr("selected", true);
            }
        }

    });
}

function change_city(pid, id, file) {                                         //改变城市
    file = file ? file : '/templates/speciality/js/Area.xml';                                    //对应xml文件
    $.ajax({
        type: "GET",
        url: file,
        dataType: "xml",
        timeout: 2000,
        error: function () {
            alert('Error loading XML document');
        },
        success: function (xml) {
            $("#txtArea").attr("disabled", true);
            $("#txtArea option").remove();
            $("#txtArea").append("<option value=''>请选择区域</option>");
            $("#txtArea").removeAttr("disabled");
            $(xml).find("Areas Area[PID=" + pid + "]").each(function (i) {
                var id = $(this).attr("ID");
                var name = $(this).attr("Name");
                $("#txtArea").append("<option value='" + id + "'>" + name + "</option>");
            });
            if (id > 0)
                $("#txtArea option[value=" + id + "]").attr("selected", true);
            else
                $("#txtArea option[index=0]").attr("selected", true);
        }

    });
}